package com.betterjr.modules.application.entity;

import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.betterjr.common.annotation.MetaData;
import com.betterjr.common.entity.BetterjrEntity;
import com.betterjr.common.selectkey.SerialGenerator;
import com.betterjr.common.utils.BTAssert;
import com.betterjr.common.utils.BetterDateUtils;
import com.betterjr.modules.account.entity.CustOperatorInfo;
import com.betterjr.modules.application.data.ApplicationConstantCollections;

/**
 * 
 * @ClassName: Application 
 * @Description:   应用表 t_ams_application
 * @author xuyp
 * @date 2017年11月17日 下午6:03:37 
 *
 */
@Access(AccessType.FIELD)
@Entity
@Table(name = "t_ams_application")
public class Application implements BetterjrEntity {

    /** 
     * @Fields serialVersionUID :  
     */
    private static final long serialVersionUID = -2830653992402210044L;

    /**
     * 流水号
     */
    @Id
    @Column(name = "ID", columnDefinition = "INTEGER")
    @MetaData(value = "流水号", comments = "流水号")
    private Long id;

    /**
     * 应用名称
     */
    @Column(name = "C_APPLICATIONNAME", columnDefinition = "VARCHAR")
    @MetaData(value = "应用名称", comments = "应用名称")
    private String applicationName;

    /**
     * 应用描述
     */
    @Column(name = "C_DESCRIPTION", columnDefinition = "VARCHAR")
    @MetaData(value = "应用描述", comments = "应用描述")
    private String description;

    /**
     * 应用图标
     */
    @Column(name = "C_APPLICATIONICON", columnDefinition = "VARCHAR")
    @MetaData(value = "应用图标", comments = "应用图标")
    private String applicationIcon;

    /**
     * 应用颜色
     */
    @Column(name = "C_APPLICATIONCOLOR", columnDefinition = "VARCHAR")
    @MetaData(value = "应用颜色", comments = "应用颜色")
    private String applicationColor;

    /**
     * 应用类型id
     */
    @Column(name = "N_APPLICATIONTYPE_ID", columnDefinition = "INTEGER")
    @MetaData(value = "应用类型id", comments = "应用类型id")
    private Long applicationTypeId;

    /**
     * 应用组id
     */
    @Column(name = "N_APPLICATIONGROUP_ID", columnDefinition = "INTEGER")
    @MetaData(value = "应用组id", comments = "应用组id")
    private Long applicationGroupId;

    /**
     * 应用所属操作机构类型
     */
    @Column(name = "C_RULELIST", columnDefinition = "VARCHAR")
    @MetaData(value = "应用所属操作机构类型", comments = "应用所属操作机构类型")
    private String ruleList;

    /**
     * 应用状态 1 待发布  2 正常 3下架 4 已停用 9已删除
     */
    @Column(name = "C_BUSINSTATUS", columnDefinition = "VARCHAR")
    @MetaData(value = "应用状态 1 待发布  2 正常 3下架 4 已停用 9已删除", comments = "应用状态 1 待发布  2 正常 3下架 4 已停用 9已删除")
    private String businStatus;

    /**
     * 注册日期
     */
    @Column(name = "C_REG_DATE", columnDefinition = "VARCHAR")
    @MetaData(value = "注册日期", comments = "注册日期")
    private String regDate;

    /**
     * 日期时间
     */
    @Column(name = "C_REG_TIME", columnDefinition = "VARCHAR")
    @MetaData(value = "日期时间", comments = "日期时间")
    private String regTime;

    /**
     * 注册操作员
     */
    @Column(name = "L_REG_OPERATORID", columnDefinition = "INTEGER")
    @MetaData(value = "注册操作员", comments = "注册操作员")
    private Long regOperatorId;

    /**
     * 注册操作员名称
     */
    @Column(name = "C_REG_OPERATORNAME", columnDefinition = "VARCHAR")
    @MetaData(value = "注册操作员名称", comments = "注册操作员名称")
    private String regOperatorName;

    /**
     * 操作机构
     */
    @Column(name = "C_OPERORG", columnDefinition = "VARCHAR")
    @MetaData(value = "操作机构", comments = "操作机构")
    private String operOrg;

    /**
     * 应用显示的类型 1 自带导航栏 2不带导航栏
     */
    @Column(name = "C_APPLICAITON_SHOWTYPE", columnDefinition = "VARCHAR")
    @MetaData(value = "应用显示的类型 1 自带导航栏 2不带导航栏", comments = "应用显示的类型 1 自带导航栏 2不带导航栏")
    private String applicationShowType;

    /**
     * 应用跳转的url地址
     */
    @Column(name = "C_SHOW_URL", columnDefinition = "VARCHAR")
    @MetaData(value = "应用跳转的url地址", comments = "应用跳转的url地址")
    private String showUrl;

    /**
     * 数据来源个人定制表中
     * 是否是个性定制应用   1 是   2 不是
     */
    @Transient
    private String proprity;

    /**
     * 数据来源个人定制表中
     * 个性定制显示的优先级 越小越优先
     */
    @Transient
    private int proprityLevel;

    /**
     * 数据来源个人定制表中
     * 是否拦截  1 默认不拦截   2 拦截
     */
    @Transient
    private String filterFalg;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getApplicationName() {
        return applicationName;
    }

    public void setApplicationName(String applicationName) {
        this.applicationName = applicationName;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getApplicationIcon() {
        return applicationIcon;
    }

    public void setApplicationIcon(String applicationIcon) {
        this.applicationIcon = applicationIcon;
    }

    public String getApplicationColor() {
        return applicationColor;
    }

    public void setApplicationColor(String applicationColor) {
        this.applicationColor = applicationColor;
    }

    public Long getApplicationTypeId() {
        return applicationTypeId;
    }

    public void setApplicationTypeId(Long applicationTypeId) {
        this.applicationTypeId = applicationTypeId;
    }

    public Long getApplicationGroupId() {
        return applicationGroupId;
    }

    public void setApplicationGroupId(Long applicationGroupId) {
        this.applicationGroupId = applicationGroupId;
    }

    public String getRuleList() {
        return ruleList;
    }

    public void setRuleList(String ruleList) {
        this.ruleList = ruleList;
    }

    public String getBusinStatus() {
        return businStatus;
    }

    public void setBusinStatus(String businStatus) {
        this.businStatus = businStatus;
    }

    public String getRegDate() {
        return regDate;
    }

    public void setRegDate(String regDate) {
        this.regDate = regDate;
    }

    public String getRegTime() {
        return regTime;
    }

    public void setRegTime(String regTime) {
        this.regTime = regTime;
    }

    public Long getRegOperatorId() {
        return regOperatorId;
    }

    public void setRegOperatorId(Long regOperatorId) {
        this.regOperatorId = regOperatorId;
    }

    public String getRegOperatorName() {
        return regOperatorName;
    }

    public void setRegOperatorName(String regOperatorName) {
        this.regOperatorName = regOperatorName;
    }

    public String getOperOrg() {
        return operOrg;
    }

    public void setOperOrg(String operOrg) {
        this.operOrg = operOrg;
    }

    public String getApplicationShowType() {
        return applicationShowType;
    }

    public void setApplicationShowType(String applicationShowType) {
        this.applicationShowType = applicationShowType;
    }

    public String getShowUrl() {
        return showUrl;
    }

    public void setShowUrl(String showUrl) {
        this.showUrl = showUrl;
    }

    public String getProprity() {
        return proprity;
    }

    public void setProprity(String proprity) {
        this.proprity = proprity;
    }

    public int getProprityLevel() {
        return proprityLevel;
    }

    public void setProprityLevel(int proprityLevel) {
        this.proprityLevel = proprityLevel;
    }

    public String getFilterFalg() {
        return filterFalg;
    }

    public void setFilterFalg(String filterFalg) {
        this.filterFalg = filterFalg;
    }

    @Override
    public String toString() {
        return "Application [id=" + id + ", applicationName=" + applicationName + ", description=" + description
                + ", applicationIcon=" + applicationIcon + ", applicationColor=" + applicationColor
                + ", applicationTypeId=" + applicationTypeId + ", applicationGroupId=" + applicationGroupId
                + ", ruleList=" + ruleList + ", businStatus=" + businStatus + ", regDate=" + regDate + ", regTime="
                + regTime + ", regOperatorId=" + regOperatorId + ", regOperatorName=" + regOperatorName + ", operOrg="
                + operOrg + ", applicationShowType=" + applicationShowType + ", showUrl=" + showUrl + ", proprity="
                + proprity + ", proprityLevel=" + proprityLevel + ", filterFalg=" + filterFalg + "]";
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((applicationColor == null) ? 0 : applicationColor.hashCode());
        result = prime * result + ((applicationGroupId == null) ? 0 : applicationGroupId.hashCode());
        result = prime * result + ((applicationIcon == null) ? 0 : applicationIcon.hashCode());
        result = prime * result + ((applicationName == null) ? 0 : applicationName.hashCode());
        result = prime * result + ((applicationShowType == null) ? 0 : applicationShowType.hashCode());
        result = prime * result + ((applicationTypeId == null) ? 0 : applicationTypeId.hashCode());
        result = prime * result + ((businStatus == null) ? 0 : businStatus.hashCode());
        result = prime * result + ((description == null) ? 0 : description.hashCode());
        result = prime * result + ((filterFalg == null) ? 0 : filterFalg.hashCode());
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        result = prime * result + ((operOrg == null) ? 0 : operOrg.hashCode());
        result = prime * result + ((proprity == null) ? 0 : proprity.hashCode());
        result = prime * result + proprityLevel;
        result = prime * result + ((regDate == null) ? 0 : regDate.hashCode());
        result = prime * result + ((regOperatorId == null) ? 0 : regOperatorId.hashCode());
        result = prime * result + ((regOperatorName == null) ? 0 : regOperatorName.hashCode());
        result = prime * result + ((regTime == null) ? 0 : regTime.hashCode());
        result = prime * result + ((ruleList == null) ? 0 : ruleList.hashCode());
        result = prime * result + ((showUrl == null) ? 0 : showUrl.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof Application)) {
            return false;
        }
        Application other = (Application) obj;
        if (applicationColor == null) {
            if (other.applicationColor != null) {
                return false;
            }
        } else if (!applicationColor.equals(other.applicationColor)) {
            return false;
        }
        if (applicationGroupId == null) {
            if (other.applicationGroupId != null) {
                return false;
            }
        } else if (!applicationGroupId.equals(other.applicationGroupId)) {
            return false;
        }
        if (applicationIcon == null) {
            if (other.applicationIcon != null) {
                return false;
            }
        } else if (!applicationIcon.equals(other.applicationIcon)) {
            return false;
        }
        if (applicationName == null) {
            if (other.applicationName != null) {
                return false;
            }
        } else if (!applicationName.equals(other.applicationName)) {
            return false;
        }
        if (applicationShowType == null) {
            if (other.applicationShowType != null) {
                return false;
            }
        } else if (!applicationShowType.equals(other.applicationShowType)) {
            return false;
        }
        if (applicationTypeId == null) {
            if (other.applicationTypeId != null) {
                return false;
            }
        } else if (!applicationTypeId.equals(other.applicationTypeId)) {
            return false;
        }
        if (businStatus == null) {
            if (other.businStatus != null) {
                return false;
            }
        } else if (!businStatus.equals(other.businStatus)) {
            return false;
        }
        if (description == null) {
            if (other.description != null) {
                return false;
            }
        } else if (!description.equals(other.description)) {
            return false;
        }
        if (filterFalg == null) {
            if (other.filterFalg != null) {
                return false;
            }
        } else if (!filterFalg.equals(other.filterFalg)) {
            return false;
        }
        if (id == null) {
            if (other.id != null) {
                return false;
            }
        } else if (!id.equals(other.id)) {
            return false;
        }
        if (operOrg == null) {
            if (other.operOrg != null) {
                return false;
            }
        } else if (!operOrg.equals(other.operOrg)) {
            return false;
        }
        if (proprity == null) {
            if (other.proprity != null) {
                return false;
            }
        } else if (!proprity.equals(other.proprity)) {
            return false;
        }
        if (proprityLevel != other.proprityLevel) {
            return false;
        }
        if (regDate == null) {
            if (other.regDate != null) {
                return false;
            }
        } else if (!regDate.equals(other.regDate)) {
            return false;
        }
        if (regOperatorId == null) {
            if (other.regOperatorId != null) {
                return false;
            }
        } else if (!regOperatorId.equals(other.regOperatorId)) {
            return false;
        }
        if (regOperatorName == null) {
            if (other.regOperatorName != null) {
                return false;
            }
        } else if (!regOperatorName.equals(other.regOperatorName)) {
            return false;
        }
        if (regTime == null) {
            if (other.regTime != null) {
                return false;
            }
        } else if (!regTime.equals(other.regTime)) {
            return false;
        }
        if (ruleList == null) {
            if (other.ruleList != null) {
                return false;
            }
        } else if (!ruleList.equals(other.ruleList)) {
            return false;
        }
        if (showUrl == null) {
            if (other.showUrl != null) {
                return false;
            }
        } else if (!showUrl.equals(other.showUrl)) {
            return false;
        }
        return true;
    }

    /**
     * 
     * @Title: saveModifyValue 
     * @Description: 填充应用新增或者修改的值 
     * @param operatorInfo
     * @param anFlag 1:新增   2：修改
     * @throws 
     * @author xuyp
     * @date 2017年11月15日 下午2:51:34
     */
    public void saveModifyValue(CustOperatorInfo operatorInfo, String anFlag) {
        BTAssert.notNull(operatorInfo, "请先登录,操作失败");
        if ("1".equals(anFlag)) {
            // 新增需要添加id
            this.setId(SerialGenerator.getLongValue("Application.id"));
            this.setBusinStatus(ApplicationConstantCollections.APPLICATION_BUSINSTATUS_NOPUBLISH);
        }

        this.setRegDate(BetterDateUtils.getNumDate());
        this.setRegOperatorId(operatorInfo.getId());
        this.setRegOperatorName(operatorInfo.getName());
        this.setRegTime(BetterDateUtils.getNumTime());
        this.setOperOrg(operatorInfo.getOperOrg());

    }

}
